package han.Chensing.CCirnosLibrary.util;

import java.io.IOException;
import java.io.InputStream;
import java.io.ObjectInputStream;
import java.io.ObjectOutputStream;
import java.io.OutputStream;

@SuppressWarnings("unchecked")
public class SerialUtil {
    @SuppressWarnings("unused")
    public static<T> T fromStream(InputStream inputStream, Class<T> tClass) throws IOException, ClassNotFoundException {
        ObjectInputStream objectInputStream=new ObjectInputStream(inputStream);
        Object object = objectInputStream.readObject();
        objectInputStream.close();
        return ((T) object);
    }

    public static void toStream(Object object, OutputStream outputStream) throws IOException {
        ObjectOutputStream objectOutputStream=new ObjectOutputStream(outputStream);
        objectOutputStream.writeObject(object);
        objectOutputStream.close();
    }
}
